package homework.no_3;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class ClientTest2 {
    public static void main(String[] args) {

        FileInputStream fis = null;
        Socket socket = null;
        try {
            fis = new FileInputStream("doc\\timg.gif");
            socket = new Socket("localhost", 8890);
            OutputStream os = socket.getOutputStream();
            int len = 0;
            byte[] bytes = new byte[1024];
            while((len = fis.read(bytes))!=-1){
                os.write(bytes,0,len);
            }

            InputStream is = socket.getInputStream();

            while((len = is.read(bytes))!=-1){
                System.out.println(new String(bytes,0,len));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                socket.shutdownOutput();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
